package cn.shop.front.util;

import cn.dev33.satoken.session.SaSession;
import cn.dev33.satoken.stp.StpUtil;
import cn.shop.base.UserInfoForSession;
import cn.shop.utils.constant.Constant;

/**
 * @author jzw
 * @since 2021-11-02 13:28
 */
public class CurrentUserUtil {

	public static UserInfoForSession getCurrentUser() {
		SaSession session = StpUtil.getSession(false);
		return session != null ? (UserInfoForSession) session.get(Constant.USER) : null;
	}

	public static Long getUserId() {
		try {
			return StpUtil.getLoginIdAsLong();
		} catch (Exception e) {
			return 0L;
		}
	}

}
